<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('Teacher/index')}">查询教师</a></li>
        <li><a href="{:url('Teacher/add_teacher')}">添加教师</a></li>
    </ul>
    <form class="well form-inline margin-top-20" method="post" action="{:url('Teacher/find_teacher')}" id="keyword">
        姓名:
        <input type="text" id="name" class="form-control" data-provide="typeahead" autocomplete="off" name="name" style="width: 200px;" value="{$param['name']|default=''}" placeholder="请输入姓名...">
		&nbsp;&nbsp;	   
	    联系方式:
        <input type="text" id="phone" class="form-control" data-provide="typeahead" autocomplete="off" name="phone" style="width: 200px;" value="{$param['phone']|default=''}" placeholder="请输入手机...">
        &nbsp;&nbsp;&nbsp;&nbsp;
		<input type="submit" class="btn btn-primary" value="搜索"/>
    </form>
	<if condition="isset($teacher_info)">
	<form class="js-ajax-form" action="" method="post">
	<input type="hidden" name="name" value="{$param['name']|default=''}"/>
	<input type="hidden" name="phone" value="{$param['phone']|default=''}"/>
        <div class="table-actions">
            <input id="edit_teacher" class="btn btn-primary" type="button" value="修改资料"></input>
            <button id="active_teacher" class="btn btn-primary js-ajax-submit" type="submit" data-action="{:url('Teacher/active_teacher')}" data-msg="您确定激活这些账号吗？">激活教师后台账号
            </button>
			<button id="ban_teacher" class="btn btn-danger js-ajax-submit" type="submit" data-action="{:url('Teacher/ban_teacher')}" data-msg="您确定禁用这些教师的后台账号吗？">禁用教师后台账号
            </button>
			<input id="timetable_teacher" class="btn btn-primary" type="button" value="教师课表"></input>
			<button id="delete_teacher" class="btn btn-danger js-ajax-submit" type="submit" style="float:right"
                    data-action="{:url('Teacher/delete_teacher')}" data-msg="您确定删除吗？">删除
            </button>
        </div>
		
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <th>教师ID</th>
                <th>后台账号ID</th>
				<th>后台账号状态</th>
                <th>姓名</th>
				<th>联系方式</th>
                <th>性别</th>
                <th>生日</th>
                <th>身份证号码</th>
                <th>入职时间</th>
                <th>登录账号</th>
                <th>登录邮箱</th>
                <th>个人简介</th>
                <!-- <th>其他信息</th> -->
            </tr>
            </thead>
            <foreach name="teacher_info" item="vo" key="i">
                <tr name='{$vo.id}'>
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.id}" title="ID:{$vo.id}">
                    </td>
                    <td><b>{$vo.id}</b></td>
					<td name="union_id_{$vo.id}">{$vo.union_id}</td>
					<td>{$vo.user_status==1?'已激活':($vo.user_status==0?'已禁用':'其他状态')}</td>
                    <td>{$vo.name}</td>
					<td>{$vo.phone}</td>
                    <td>{$vo.sex==1 ? '男' : ($vo.sex==2 ? '女' : '未知')}</td>
                    <td>{$vo.birthday|default='未知'}</td>
                    <td>{$vo.IDcard|default='未知'}</td>
					<td>{$vo.entry_time}</td>
					<td>{$vo.user_login}</td>
					<td>{$vo.user_email}</td>
					<td><a href="{:url('portal/article/introduction_article',array('id'=>$vo.id))}" class="btn btn-primary" target="blank">查看</a></td>
                </tr>
            </foreach>
        </table>
		
        <ul class="pagination">{$page|default=''}</ul>
	</form>
	</if>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/bootstrap-typeahead.js"></script>
<script>

	$(function(){
		$("#edit_teacher").click(function(){
			var ids = [];
			$("input[name='ids[]']").each(function () {
				if ($(this).is(':checked')) {
					ids.push($(this).val());
				}
			});
			if (ids.length == 1){
				var url = "{:url('Teacher/edit_teacher','',false,true)}" + "/id/" + ids;
				<!-- alert(url); -->
				window.location.href = url;
			}
			else{
				alert('请选择一个教师进行编辑');
			}
		});
		$("#timetable_teacher").click(function(){
			var ids = [];
			$("input[name='ids[]']").each(function () {
				if ($(this).is(':checked')) {
					ids.push($(this).val());
				}
			});
			if (ids.length == 1){
			var id = $("td[name='union_id_"+ids+"']").html();
				var url = "{:url('portal/wxview/get_timetable','',false,true)}" + "/id/" + id;
				<!-- alert(url); -->
				window.location.href = url;
			}
			else{
				alert('请选择一个教师查看课表！');
			}
		});
	});

	$(function(){
		$("tr[name]").click(function(){
			var id = $(this).attr("name");
			var is_check = $("input[value='"+id+"']").prop("checked");
			if(is_check){
				$("input[value='"+id+"']").prop("checked",false);
				$(this).prop("class",false);
			}
			else{
				$("input[value='"+id+"']").prop("checked",true);
				$(this).prop("class","success");
			}
		});
	});
	
	$(function(){
		$('#name').typeahead({
			source: function (query, process) {
				return $.ajax({
					url: "{:url('Teacher/find_teacher_name','',false,true)}",
					type: 'post',
					data: {'name': query},
					success: function (result) {
						var obj = $.parseJSON(result);
						var resultList = [];
						$.each(obj,function(i,n){
							resultList[i] = JSON.stringify(n);
						});
						return process(resultList);
					},
				});
			},
			highlighter: function (obj) {
				var item = JSON.parse(obj);
				var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
				return item.name.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
					return '<strong>' + match + '</strong>'
				}) + item.phone;
			},
			updater: function (obj) {
				var item = JSON.parse(obj);
				$('#phone').val(item.phone);
				$('#name').val(item.name);
				$("option").prop("selected",false);
				$("#keyword").submit();
				return item.name;
			},
			items: 5, //显示5条
			delay: 500, //延迟时间
		});
	});
	
	$(function(){
		$('#phone').typeahead({
			source: function (query, process) {
				return $.ajax({
					url: "{:url('Teacher/find_teacher_phone','',false,true)}",
					type: 'post',
					data: {'phone': query},
					success: function (result) {
						var obj = $.parseJSON(result);
						var resultList = [];
						$.each(obj,function(i,n){
							resultList[i] = JSON.stringify(n);
						});
						return process(resultList);
					},
				});
			},
			highlighter: function (obj) {
				var item = JSON.parse(obj);
				var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
				return item.name.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
					return '<strong>' + match + '</strong>'
				}) + item.phone;
			},
			updater: function (obj) {
				var item = JSON.parse(obj);
				$('#name').val(item.name);
				$('#phone').val(item.phone);
				$("option").prop("selected",false);
				$("#keyword").submit();
				return item.phone;
			},
			items: 5, //显示5条
			delay: 500, //延迟时间
		});
	});
</script>
</body>
</html>